package com.nuedu.corejava.ch9.homework;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class HomeWork {
	public static void main(String[] args) {
		System.out.println("请输入商品的生产日期：（YYYY-MM-DD）");
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Scanner scanner = new Scanner(System.in);
		String produced = scanner.nextLine();
		System.out.println("请输入保质期");
		int b = scanner.nextInt();
		Date pDate;
		try {
			pDate = dateFormat.parse(produced);
			Calendar c = Calendar.getInstance();
			c.setTime(pDate);
			c.add(Calendar.DATE, b);
			Date nowDate = new Date();
			Date guo_Date = c.getTime();
			long time = guo_Date.getTime()- nowDate.getTime() ;
			long day = time / 24 / 60 / 60 / 1000;
			String nowString = dateFormat.format(new Date());
			String guoString = dateFormat.format(guo_Date);
			System.out.println("今天日期为" + nowString);
			System.out.println("过期日期为" + guoString);
			
			if (nowDate.before(guo_Date)) {

				System.out.println("未过期");
				System.err.println("还有" + day + "过期");
			} else {
				System.out.println("已过期");
			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}

}
